home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / 3dvect37.zip / QB.ZIP / NORMAL.BAS < prev    next >
BASIC Source File  |  1993-10-08  |  2KB  |  74 lines

  1. DECLARE FUNCTION f$ (g!)
  2.  
  3. PRINT "Calculate Surface Normal Based on 3 Points"
  4. PRINT
  5. PRINT "Can be used to pre-calculate normals for  objects.   Also  could"
  6. PRINT "be used to test if a multi-sided  polygon  is  flat  or  curved."
  7. PRINT "(curved ploygons can't be plotted well, flat polygons will  have"
  8. PRINT "the same  surface  normal  regardless  of  points  selected  for"
  9. PRINT "calculation)."
  10. PRINT
  11. PRINT "Remember, the routine pre_cal_lambert will calculate all surface"
  12. PRINT "normals for you.!!!"
  13. PRINT
  14.  
  15. INPUT "Filename to output data words to:(enter = none)"; a$
  16.  
  17. goagain:
  18. PRINT
  19. PRINT "Enter co-ordinates of first 3 points in polygon (counter-clockwise)"
  20. PRINT "(remember, negative y is up)"
  21. PRINT
  22.  
  23. IF a$ <> "" AND z = 0 THEN OPEN a$ FOR OUTPUT AS #1: z = 1
  24.  
  25. INPUT x1, y1, z1
  26. INPUT x2, y2, z2
  27. INPUT x3, y3, z3
  28.  
  29. x2 = x2 - x1
  30. y2 = y2 - y1
  31. z2 = z2 - z1
  32.  
  33. x3 = x3 - x1
  34. y3 = y3 - y1
  35. z3 = z3 - z1
  36.  
  37. x = y2 * z3 - z2 * y3
  38. y = z2 * x3 - x2 * z3
  39. z = x2 * y3 - y2 * x3
  40.  
  41. a = SQR(x ^ 2 + y ^ 2 + z ^ 2) / 255
  42.  
  43. x = INT(x / a + .5)
  44. y = INT(y / a + .5)
  45. z = INT(z / a + .5)
  46.  
  47. PRINT
  48. PRINT "Your Gouraud/Lambert shading values are:"
  49.  
  50. PRINT "x="; x; " y="; y; " z="; z
  51. PRINT "  dw "; f$(x); ","; f$(y); ","; f$(z)
  52. IF a$ <> "" THEN PRINT #1, "  dw "; f$(x); ","; f$(y); ","; f$(z)
  53.  
  54. d$(0) = "That was Fun, Lets do it again!"
  55. d$(1) = "Hey, I liked that, you got more?"
  56. d$(2) = "OOooo, Thats and interesting number isn't it, lets do another one"
  57. d$(3) = "Pre_cal_lambert does this for you, you know..."
  58.  
  59. PRINT
  60. PRINT d$(RND * 3)
  61. GOTO goagain:
  62.  
  63. REM Dot Product...  A dot B=AX*BX+AY*BY+AZ*BZ=some scalar
  64.  
  65. REM Normalize...A<bar>=[AX/|A|,AY/|A|,AZ/|A|]=some vector. Each component is
  66. REM divided by the length of the vector (sqrt(x*x+y*y+z*z)).
  67.  
  68. FUNCTION f$ (g)
  69.  
  70.       f$ = LTRIM$(RTRIM$(STR$(g)))
  71.  
  72. END FUNCTION
  73.  
  74.